package com.lanou.controller.T8TController;

import com.github.pagehelper.PageInfo;
import com.lanou.bean.T8Tcommodity.Brand;
import com.lanou.bean.T8Tcommodity.Commodity;
import com.lanou.service.T8TService.T8TService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by dllo on 18/3/17.
 */
@Controller
public class T8TController {
    @Resource
    private T8TService T8TService;
    //根据分类查找商品
    //SD:销量降序
    //PA:价格升序
    //C1:首页主导航
    //C2:次页导航大标题
    //C3:大标题下系分类
    //C4:品牌
    //priceMax:价格最高
    //priceMin:价格最低
    @ResponseBody
    @RequestMapping(value = "/findCommodity")
    public List<Commodity> findCommodity(

                                         @RequestParam(value = "SD",required = false) Integer SD,
                                         @RequestParam(value = "PA",required = false) Integer PA,
                                         @RequestParam(value = "C1",required = false) Integer C1ID,
                                         @RequestParam(value = "C2",required = false) Integer C2ID,
                                         @RequestParam(value = "C3",required = false) Integer C3ID,
                                         @RequestParam(value = "C4",required = false) Integer C4ID,
                                         @RequestParam(value = "priceMax",required = false) Double priceMax,
                                         @RequestParam(value = "priceMin",required = false) Double priceMin
    ) {
        return T8TService.findCommodity(SD,PA,C1ID,C2ID,C3ID,C4ID,priceMax,priceMin);
    }
    //根据商品ID查找商品
    @ResponseBody
    @RequestMapping(value = "/findCommodityBycommodityID")
    public Commodity findCommodityBycommodityID(@RequestParam(value = "commodityID") Integer commodityID){
        return T8TService.findCommodityBycommodityID(commodityID);
    }
    //根据分类查找商品(分页)
    //PN：第几页
    //PS:每页数据条数
    //SD:销量降序
    //PA:价格升序
    //C1:首页主导航
    //C2:次页导航大标题
    //C3:大标题下系分类
    //C4:品牌
    //priceMax:价格最高
    //priceMin:价格最低
    @ResponseBody
    @RequestMapping(value = "/findCommodityPage")
    public PageInfo<Commodity> findCommodityPage(@RequestParam(value = "PN",required = false) Integer PN,
                                                 @RequestParam(value = "PS",required = false) Integer PS,
                                                 @RequestParam(value = "SD",required = false) Integer SD,
                                                 @RequestParam(value = "PA",required = false) Integer PA,
                                                 @RequestParam(value = "C1",required = false) Integer C1ID,
                                                 @RequestParam(value = "C2",required = false) Integer C2ID,
                                                 @RequestParam(value = "C3",required = false) Integer C3ID,
                                                 @RequestParam(value = "C4",required = false) Integer C4ID,
                                                 @RequestParam(value = "priceMax",required = false) Double priceMax,
                                                 @RequestParam(value = "priceMin",required = false) Double priceMin) {
        return T8TService.findCommodityPage(PN,PS,SD,PA,C1ID,C2ID,C3ID,C4ID,priceMax,priceMin);
    }

    //根据分查找品牌
    //C2:次页导航大标题
    //C3:大标题下系分类
    @ResponseBody
    @RequestMapping(value = "/findBrand")
    public List<Brand> findBrand(@RequestParam(value = "C2",required = false)Integer C2ID,
                                 @RequestParam(value = "C3",required = false)Integer C3ID){
        return T8TService.findBrand(C2ID,C3ID);
    }

}
